package com.spsoft.vatoutinv.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.spsoft.core.annotation.AnonymousAccess;
import com.spsoft.core.annotation.Log;
import com.spsoft.core.controller.BaseController;
import com.spsoft.core.enums.LogActionType;
import com.spsoft.core.enums.LogMenuEnum;
import com.spsoft.core.model.Result;
import com.spsoft.core.utils.SecurityUtils;
import com.spsoft.vatoutinv.model.dto.vmshzqrdmanage.VmsApprovalHzqrdPageDto;
import com.spsoft.vatoutinv.model.dto.vmshzqrdmanage.VmsApprovalHzqrdTotalDto;
import com.spsoft.vatoutinv.model.dto.vmshzqrdmanage.VmsHclzfpPageDto;
import com.spsoft.vatoutinv.model.vo.vmsfulloutinvoice.VmsFullOutInvoicePageVO;
import com.spsoft.vatoutinv.model.vo.vmshzqrdmanage.VmsApprovalHzqrdTotalSimpleVo;
import com.spsoft.vatoutinv.model.vo.vmshzqrdmanage.VmsApprovalHzqrdVo;
import com.spsoft.vatoutinv.service.vmshzqrdmanage.VmsHzqrdApplyService;
import com.spsoft.vatoutinv.service.vmsnvattrandtadvaltax.VmsNvatTrandtadvaltaxsepService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 红字确认单申请 前端控制器
 * </p>
 *
 * @author chenxudong
 * @since 2024-01-02
 */
@RestController
@Api(tags = {"红字确认单申请管理"})
@RequestMapping("/vmsHzqrdApply")
@RequiredArgsConstructor
@Validated
@Slf4j
public class VmsHzqrdApplyController extends BaseController {

    public static final String LOG_MSG = "(红字确认单申请控制层)";

    private final VmsHzqrdApplyService vmsHzqrdApplyService;

    private final VmsNvatTrandtadvaltaxsepService nvatTrandtadvaltaxsepService;

    @ApiOperation("校验纳税人基本信息和风险信息")
    @AnonymousAccess(value = "/checkInfoAndRisk", method = RequestMethod.POST, permissionCode = "VMS_HZQRDSQ")
    @Log(value = "校验纳税人基本信息和风险信息", type = LogActionType.SELECT, menuName = LogMenuEnum.HZQRD_APPLY)
    public Result<Object> checkInfoAndRisk() {
        log.info("{}校验纳税人基本信息和风险信息", LOG_MSG);
        nvatTrandtadvaltaxsepService.checkStatus("3");
        return Result.OK();
    }

    @ApiOperation("主界面-分页查询")
    @AnonymousAccess(value = "/pageApply", method = RequestMethod.POST, permissionCode = "VMS_HZQRDSQ")
    @Log(value = "红字确认单申请主界面-分页查询", type = LogActionType.SELECT, menuName = LogMenuEnum.HZQRD_APPLY)
    public Result<IPage<VmsApprovalHzqrdVo>> pageApply(@RequestBody VmsApprovalHzqrdPageDto pageDto) {
        log.info("{}主界面分页查询，入参：{}", LOG_MSG, JSONObject.toJSONString(pageDto));
        pageDto.setCreatBy(SecurityUtils.getUserCode());
        pageDto.setDeptCode(SecurityUtils.getDeptCode());
        return vmsHzqrdApplyService.pageApply(pageDto);
    }

    @ApiOperation("红冲蓝字发票选择页面-分页查询")
    @AnonymousAccess(value = "/pageInvoice", method = RequestMethod.POST, permissionCode = "VMS_HZQRDSQ")
    @Log(value = "红冲蓝字发票选择页面-分页查询", type = LogActionType.SELECT, menuName = LogMenuEnum.HZQRD_APPLY)
    public Result<IPage<VmsFullOutInvoicePageVO>> pageInvoice(@RequestBody VmsHclzfpPageDto pageDto) {
        log.info("{}红冲蓝字发票选择页面-分页查询，入参：{}", LOG_MSG, JSONObject.toJSONString(pageDto));
        return vmsHzqrdApplyService.pageInvoice(pageDto);
    }

    @ApiOperation("新增子界面-快速添加")
    @AnonymousAccess(value = "/fastAdd", method = RequestMethod.POST, permissionCode = "VMS_HZQRDSQ")
    @Log(value = "新增子界面-快速添加", type = LogActionType.SELECT, menuName = LogMenuEnum.HZQRD_APPLY)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lzfpdm", value = "蓝字发票代码", dataTypeClass = String.class, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "lzfphm", value = "蓝字发票号码", dataTypeClass = String.class, dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "applyId", value = "审批流id", dataTypeClass = Long.class, dataType = "Long", paramType = "query")
    })
    public Result<VmsApprovalHzqrdTotalSimpleVo> fastAdd(@RequestParam(value = "lzfpdm", required = false) String lzfpdm,
                                                         @RequestParam(value = "lzfphm") String lzfphm,
                                                         @RequestParam(value = "applyId", required = false) Long applyId) {
        log.info("{}新增子界面-快速添加，蓝字发票代码：{}，蓝字发票号码：{}，审批流id：{}", LOG_MSG, lzfpdm, lzfphm, applyId);
        return vmsHzqrdApplyService.fastAdd(lzfpdm, lzfphm, applyId);
    }

    @ApiOperation("保存红字确认单申请信息")
    @AnonymousAccess(value = "/saveApply", method = RequestMethod.POST, permissionCode = "VMS_FULL_HZQRD_APPLY_SAVE")
    @Log(value = "保存红字确认单申请信息", type = LogActionType.ADD, menuName = LogMenuEnum.HZQRD_APPLY)
    public Result<Object> saveApply(@RequestBody @Validated VmsApprovalHzqrdTotalDto applyDto) {
        log.info("{}保存红字确认单申请信息，入参：{}", LOG_MSG, JSONObject.toJSONString(applyDto));
        return vmsHzqrdApplyService.saveApply(applyDto);
    }

    @ApiOperation("撤销红字确认单申请")
    @AnonymousAccess(value = "/revokeApply", method = RequestMethod.POST, permissionCode = "VMS_FULL_HZQRD_APPLY_REVOKE")
    @Log(value = "撤销红字确认单申请", type = LogActionType.UPDATE, menuName = LogMenuEnum.HZQRD_APPLY)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "确认单id", dataTypeClass = Long.class, dataType = "Long", required = true)
    })
    public Result<Object> revokeApply(@RequestParam(value = "id") Long id) {
        log.info("{}撤销红字确认单申请，红字确认单id：{}", LOG_MSG, id);
        return vmsHzqrdApplyService.revokeApply(id);
    }

    @ApiOperation("获取红字确认单申请信息详情")
    @AnonymousAccess(value = "/getApplyDetail", method = RequestMethod.POST, permissionCode = "VMS_HZQRDSQ")
    @Log(value = "获取红字确认单申请信息详情", type = LogActionType.SELECT, menuName = LogMenuEnum.HZQRD_APPLY)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "applyId", value = "审批流id", dataTypeClass = Long.class, dataType = "Long", required = true)
    })
    public Result<VmsApprovalHzqrdTotalSimpleVo> getApplyDetail(@RequestParam(value = "applyId") Long applyId) {
        log.info("{}获取红字确认单申请信息详情，审批流id：{}", LOG_MSG, applyId);
        return vmsHzqrdApplyService.getApplyDetail(applyId);
    }

    // 此接口造数据用
    @ApiOperation("此接口造数据用")
    @AnonymousAccess(value = "/hzqrdApply", method = RequestMethod.POST, permissionCode = "")
    @Log(value = "调用乐企数电红字确认单申请接口完成申请", type = LogActionType.ADD, menuName = LogMenuEnum.HZQRD_APPLY)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "审批流id", dataTypeClass = Long.class, dataType = "Long", required = true)
    })
    public Result<Object> hzqrdApply(@RequestParam(value = "id") Long id) {
        log.info("{}调用乐企数电红字确认单申请接口完成申请,id：{}", LOG_MSG, id);
        return vmsHzqrdApplyService.hzqrdApply(id);
    }
}

